<?php
declare(strict_types=1);

namespace Modules\Inventory\Http\Controllers;

use Catch\Base\CatchController as Controller;
use Modules\Inventory\Models\TransferOrder;
use Illuminate\Http\Request;use Modules\Inventory\Repository\TransferOrderRepository;


class TransferOrderController extends Controller
{
    public function __construct(
        protected readonly TransferOrder $model
    ){}

    /**
     * @param Request $request
     * @return mixed
     */
    public function index(Request $request): mixed
    {
        return TransferOrderRepository::getList($request->all());
    }

    /**
     * 直接调拨提交
     * @param Request $request
     * @return mixed
     */
    public function store(Request $request)
    {
        return TransferOrderRepository::storeBy($request->post());
    }

    /**
     * 分步式调出提交
     * @param Request $request
     * @return bool
     * @throws Throwable
     */
    public function setByOut(Request $request){
        return TransferOrderRepository::setByOut($request->post());
    }

    /**
     * 根据箱号查询未完成的分步式调拨单
     * @param $lotnum
     * @param Request $request
     * @return mixed
     */
    public function getOutByLotnum($lotnum,Request $request){
        return TransferOrderRepository::getOutByLotnum($lotnum,$request->all());
    }

    /**
     * 分步式调入提交
     * @param Request $request
     * @return mixed
     */
    public function setByInbound(Request $request){
        return TransferOrderRepository::setByInbound($request->post());
    }

    /**
     * @param $id
     * @return mixed
     */
    public function show($id)
    {
        return $this->model->firstBy($id);
    }

    /**
     * @param Request $request
     * @param $id
     * @return mixed
     */
    public function update($id, Request $request)
    {
        return $this->model->updateBy($id, $request->all());
    }

    /**
     * @param $id
     * @return mixed
     */
    public function destroy($id)
    {
        return $this->model->deleteBy($id);
    }
}
